function utilAlert(msg, iconType) {
    uni.showToast({
        title: msg == null ? "" : msg,
        icon: "none",
        duration: 1500
    });
    return;
};

function utilLoading(tip,mask){
    uni.showLoading({
        title: tip?tip:'加载中',
        mask:mask?mask:false
    });

    setTimeout(function (){
         uni.hideLoading();
    },10000)
};
//  ['vuex_userInfo', 'vuex_token','vuex_deviceMode','vuex_loginParam'];
function changeVuexStatu(that,count,price,tempShopCarData){
	//console.log("改变缓存缓存");
	that.$u.vuex('vuex_totalCount',count);
	that.$u.vuex('vuex_totalPrice',price);
	if(tempShopCarData!=null&&tempShopCarData!=undefined){
		that.$u.vuex('vuex_shopCarData',tempShopCarData);
	}
}
//数字取两位小数
function toDecimal(x) {
	var f = parseFloat(x);
	if (isNaN(f)) {
	return false;
	}
	var f = Math.round(x*100)/100;
	var s = f.toString();
	var rs = s.indexOf('.');
	if (rs < 0) {
	rs = s.length;
	s += '.';
	}
	while (s.length <= rs + 2) {
	s += '0';
	}
	return s;
}


//字节转换
function byteConvert(bytes) {
      //console.log("字节量"+bytes);
      if (isNaN(bytes)) {
        return '';
      }
      var symbols = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
      var exp = Math.floor(Math.log(bytes)/Math.log(2));
      if (exp < 1) {
        exp = 0;
      }
      var i = Math.floor(exp / 10);
      bytes = bytes / Math.pow(2, 10 * i);
      if (bytes.toString().length > bytes.toFixed(2).toString().length) {
        bytes = bytes.toFixed(2);
      }
      return bytes + ' ' + symbols[i];
}


function getScrollViewHeigh(that){
	let windowHeight=that.$u.sys().windowHeight;
	let statusBar= uni.getSystemInfoSync().statusBarHeight;
	console.log("===sstatusBar===",statusBar);
	let height=(windowHeight-statusBar);
	return height;
}


function dateFormatTime(date,j='/',l='Ymd H:i:s'){
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  if(l == 'Ymd'){
    return [year, month, day].map(formatNumber).join(j)
  }else{
    return [year, month, day].map(formatNumber).join(j) + ' ' + [hour, minute, second].map(formatNumber).join(':')
  }
}

function formatNumber(n){
  n = n.toString();
  return n[1] ? n : '0' + n;
}

function timestampToDateStr(timestamp,j = '/',l='Ymd'){
  if(timestamp.length == 10){
    timestamp = timestamp*1000;
  }
  let date = new Date(timestamp);
  return formatTime(date,j,l)
}



module.exports = {
	utilAlert: function (msg, iconType) {
			return utilAlert(msg, iconType);
	},
	utilLoading:function (tip,mask){
	    return utilLoading(tip, mask);
	},
	changeVuexStatu:function(that,count,price){
		return changeVuexStatu(that,count,price);
	},
	byteConvert:function(bytes){
		return byteConvert(bytes);
	},
	toDecimal:function(num){
		return toDecimal(num)
	},
	getScrollViewHeigh:function(that){
		return getScrollViewHeigh(that);
	},
	dateFormatTime:function(date,j='/',l='Ymd H:i:s'){
		return dateFormatTime(date,j='/',l='Ymd H:i:s');
	},
	timestampToDateStr:function(timestamp,j='/',l='Ymd H:i:s'){
		return timestampToDateStr(timestamp,j='/',l='Ymd H:i:s');
	},
}	
